package com.hgc.ch01.base;

/**
 * Created by 01367627 on 2019/7/5.
 */
public class SafeEndThread {
    private static class MyThread extends Thread{
        public MyThread(String name) {
            super(name);
        }

        @Override
        public void run() {
            while (!isInterrupted()){
                System.out.println(getName() + " is running.");
            }
            System.out.println(getName() + " run over. InterruptedFlag is :" + isInterrupted());
        }
    }

    public static void main(String[] args) throws InterruptedException {
        MyThread myThread = new MyThread("t1");
        myThread.start();
        Thread.sleep(3000);
        myThread.interrupt();
    }
}
